<template>
  <el-card>
    <div class="dashboard">
    <div class="container">
      <!-- 左侧内容 -->
      <div class="left">
        <div class="panel">
          <!-- 个人信息 -->
          <div class="user-info">
            <img class="avatar" src="../../assets/images/logo.png" alt="" />
            <div class="company-info">
              <div class="title">医院挂号后台管理系统</div>
              <div class="depart">
                {{ userStore.userInfo?.name }} ｜
                {{ userStore.userInfo?.TweDepart }}
              </div>
            </div>
          </div>
          <!-- 代办 -->
          <div class="todo-list">
            <div class="todo-item">
              <span>医院用户总人数</span>
              <!-- 起始值 终点值  滚动时间 -->
              <CountTo :start-val="0" :end-val="randomNumber()" :duration="2500" ></CountTo>
            </div>
            <div class="todo-item">
              <span>医院医生</span>
              <CountTo :start-val="0" :end-val="randomThreeNumber()" :duration="2500" ></CountTo>
            </div>
            <div class="todo-item">
              <span>医院今日挂号数量</span>
              <CountTo :start-val="0" :end-val="randomThreeNumber()" :duration="2500" ></CountTo>
              <!-- <span>345 </span> -->
            </div>
            <div class="todo-item">
              <span>医院今日挂号收入</span>
          
                <CountTo :start-val="0" :end-val="randomNumber()" :duration="2500" ></CountTo>
            
              
            </div>

            <div class="todo-item">
              <span>接口总访问</span>
              <CountTo :start-val="0" :end-val="randomFiveNumber()" :duration="2500" ></CountTo>
            </div>
          </div>
        </div>
        <!-- 快捷入口 -->
        <div class="panel">
          <div class="panel-title">快捷入口</div>
          <div class="quick-entry">
            <div class="entry-item">
              <div class="entry-icon approval" />
              <span
                ><router-link to="/idcard/people" class="link">
                  身份证审核
                </router-link>
              </span>
            </div>
            <div class="entry-item">
              <div class="entry-icon social" />
              <span>
                <router-link to="/Notice" class="link">公告管理</router-link>
              </span>
            </div>
            <div class="entry-item">
              <div class="entry-icon role" />
              <span>
                <router-link to="/authority/job" class="link"
                  >角色与菜单管理</router-link
                >
              </span>
            </div>
            <div class="entry-item">
              <div class="entry-icon salary" />
              <span>
                <router-link to="/Order" class="link">订单管理</router-link>
              </span>
            </div>
            <div class="entry-item">
              <div class="entry-icon bpm" />
              <span>
                <router-link to="/Order" class="link">轮播图管理</router-link>
              </span>
            </div>
          </div>
        </div>
        <!-- 图表数据 -->
        <div class="panel">
          <div class="panel-title">近月科室预约情况</div>
          <div class="chart-container">
            <div class="chart">
              <!-- 图表 -->
            </div>
          </div>
        </div>
        <!-- 图表数据 -->
      </div>
      <!-- 右侧内容 -->
      <div class="right">
        <!-- 帮助链接 -->
        <div class="panel">
          <div class="help">
            <div class="help-right">
              <h1>日历</h1>
              <div class="calendar">
                <!-- <el-calendar /> -->
                <el-calendar />
              </div>
            </div>
          </div>
        </div>
        <!-- 通知公告 -->
        <div class="panel">
          <div class="panel-title">用户挂号科室比例</div>
          <div class="charts"></div>
        </div>
      </div>
    </div>
  </div>
  </el-card>
</template>

<script setup>
import { onMounted } from "vue";
import useUserStore from "@/stores/modules/userStore";
import * as echarts from 'echarts'
import { CountTo } from "vue3-count-to";
import { randomNumber ,randomThreeNumber , randomFiveNumber } from '@/utils/number'
const userStore = useUserStore();
onMounted(() => {
  let myChart1 = echarts.init(document.querySelector(".chart"));
  let myChart2 = echarts.init(document.querySelector(".charts"));
  var colorList = ["#f36c6c", "#e6cf4e", "#20d180", "#0093ff"];
  var datas = [
    {
      value: 350,
      name: "心血管科",
    },
    {
      value: 280,
      name: "神经科",
    },
    {
      value: 235,
      name: "消化内科",
    },
    {
      value: 190,
      name: "呼吸科",
    },
    {
      value: 190,
      name: "骨科",
    },
    {
      value: 175,
      name: "儿科",
    },
    {
      value: 150,
      name: "妇产科",
    },
    {
      value: 95,
      name: "耳鼻喉科",
    },
  ];

  let option = {
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "shadow",
      },
    },
    legend: {
      show: false,
    },
    grid: {
      left: 0,
      right: "5%",
      top: "5%",
      bottom: "2%",
      containLabel: true,
    },
    xAxis: {
      show: false,
      type: "value",
    },
    yAxis: [
      {
        type: "category",
        inverse: true,
        axisLine: {
          show: false,
        },
        axisTick: {
          show: false,
        },
        axisPointer: {
          label: {
            show: true,
            margin: 30,
          },
        },
        data: datas.map((item) => item.name),
        axisLabel: {
          margin: 50,
          fontSize: 14,
          align: "left",
          color: "#333",
          rich: {
            a1: {
              color: "#fff",
              backgroundColor: colorList[0],
              width: 30,
              height: 30,
              align: "center",
              borderRadius: 2,
            },
            a2: {
              color: "#fff",
              backgroundColor: colorList[1],
              width: 30,
              height: 30,
              align: "center",
              borderRadius: 2,
            },
            a3: {
              color: "#fff",
              backgroundColor: colorList[2],
              width: 30,
              height: 30,
              align: "center",
              borderRadius: 2,
            },
            b: {
              color: "#fff",
              backgroundColor: colorList[3],
              width: 30,
              height: 30,
              align: "center",
              borderRadius: 2,
            },
          },
          formatter: function (params) {
            var index = datas.map((item) => item.name).indexOf(params);
            index = index + 1;
            if (index - 1 < 3) {
              return ["{a" + index + "|" + index + "}"].join("\n");
            } else {
              return ["{b|" + index + "}"].join("\n");
            }
          },
        },
      },
      {
        type: "category",
        inverse: true,
        axisTick: "none",
        axisLine: "none",
        show: true,
        data: datas.map((item) => item.value),
        axisLabel: {
          show: true,
          fontSize: 14,
          color: "#333",
          formatter: "{value}",
        },
      },
    ],
    series: [
      {
        z: 2,
        name: "value",
        type: "bar",
        barCategoryGap: "40%",
        barGap: "20%",
        barWidth: 16,
        data: datas.map((item, i) => {
          var itemStyle = {
            color: i > 3 ? colorList[3] : colorList[i],
            barBorderRadius: [10, 10, 10, 10],
          };
          return {
            value: item.value,
            itemStyle: itemStyle,
          };
        }),
        label: {
          normal: {
            color: "#666",
            show: true,
            position: [0, "-18px"],
            textStyle: {
              fontSize: 14,
            },
            formatter: function (a, b) {
              return a.name;
            },
          },
        },
      },
    ],
  };
  var ydata = [
    {
      name: "心血管科",
      value: 18,
    },
    {
      name: "神经科",
      value: 16,
    },
    {
      name: "消化内科",
      value: 15,
    },
    {
      name: "呼吸科",
      value: 14,
    },
    {
      name: "骨科",
      value: 10,
    },
    {
      name: "儿科",
      value: 7.9,
    },
    {
      name: "妇产科",
      value: 6.7,
    },
    {
      name: "眼科",
      value: 6,
    },
    {
      name: "耳鼻喉科",
      value: 4.5,
    },
    {
      name: "口腔科",
      value: 3,
    },
  ];
  var color = [
    "#8d7fec",
    "#5085f2",
    "#e75fc3",
    "#f87be2",
    "#f2719a",
    "#fca4bb",
    "#f59a8f",
    "#fdb301",
    "#57e7ec",
    "#cf9ef1",
  ];
  var xdata = [
    "心血管科",
    "神经科",
    "消化内科",
    "呼吸科",
    "骨科",
    "儿科",
    "妇产科",
    "眼科",
    "耳鼻喉科",
    "口腔科",
  ];

  let option2 = {
    // backgroundColor: "rgba(255,255,255,1)",
    color: color  ,
    legend: {
      orient: "vartical",
      x: "left",
      top: "center",
      left: "60%",
      bottom: "0%",
      data: xdata,
      itemWidth: 8,
      itemHeight: 8,
      itemGap: 16,


      formatter: function (name) {
        return "" + name;
      },
    },
    series: [
      {
        type: "pie",
        clockwise: false, //饼图的扇区是否是顺时针排布
        minAngle: 2, //最小的扇区角度（0 ~ 360）
        radius: ["40%", "70%"],
        center: ["30%", "50%"],
        avoidLabelOverlap: false,
        itemStyle: {
          //图形样式
          normal: {
            borderColor: "#ffffff",
            borderWidth: 6,
          },
        },
        label: {
          normal: {
            show: false,
            position: "center",
            formatter: "{text|{b}}\n{c} ({d}%)",
            rich: {
              text: {
                color: "#666",
                fontSize: 14,
                align: "center",
                verticalAlign: "middle",
                padding: 8,
              },
              value: {
                color: "#8693F3",
                fontSize: 24,
                align: "center",
                verticalAlign: "middle",
              },
            },
          },
          emphasis: {
            show: true,
            textStyle: {
              fontSize: 24,
            },
          },
        },
        data: ydata,
      }
    ],
  };
  myChart2.setOption(option2);
  myChart1.setOption(option);
  setTimeout(function () {
    myChart2.on("mouseover", function (params) {
      if (params.name == ydata[0].name) {
        myChart2.dispatchAction({
          type: "highlight",
          seriesIndex: 0,
          dataIndex: 0,
        });
      } else {
        myChart2.dispatchAction({
          type: "downplay",
          seriesIndex: 0,
          dataIndex: 0,
        });
      }
    });

    myChart2.on("mouseout", function (params) {
      myChart2.dispatchAction({
        type: "highlight",
        seriesIndex: 0,
        dataIndex: 0,
      });
    });
    myChart2.dispatchAction({
      type: "highlight",
      seriesIndex: 0,
      dataIndex: 0,
    });
  }, 1000);
  
});
</script>

<style scoped lang="scss">
.dashboard {
  // background: #f5f6f8;
  width: 100%;
  min-height: calc(100vh - 80px);

  // :deep('.el-calendar-day') {
  //   height: 40px;
  // }
  // :deep('.el-calendar-table__row td'),
  // :deep('.el-calendar-table tr td:first-child'),
  // :deep('.el-calendar-table__row td.prev')  {
  //   border: none;
  // }
  .date-content {
    height: 40px;
    text-align: center;
    line-height: 40px;
    font-size: 14px;
  }
  .date-content .rest {
    color: #fff;
    border-radius: 50%;
    background: rgb(250, 124, 77);
    width: 20px;
    height: 20px;
    line-height: 20px;
    display: inline-block;
    font-size: 12px;
    margin-left: 10px;
  }
  .date-content .text {
    width: 20px;
    height: 20px;
    line-height: 20px;
    display: inline-block;
  }
  // :deep('.el-calendar-table td.is-selected') .text {
  //   background: #409eff;
  //   color: #fff;
  //   border-radius: 50%;
  // }
  // :deep('.el-calendar__header') {
  //   display: none;
  // }
  .container {
    display: flex;
    .right {
      width: 40%;
      .panel {
        margin-left: 8px;
      }
      :nth-child(1) {
        margin-top: 0;
      }
    }
    .left {
      flex: 1;
      :nth-child(1) {
        margin-top: 0;
      }
    }
    .panel {
      // background-color: #fff;

      margin-top: 8px;
      padding: 20px;
      .panel-title {
        font-size: 16px;
        color: #383c4e;
        font-weight: 500;
      }
      .charts {
        width: 100%;
        height: 300px;
      }
      // 用户信息样式
      .user-info {
        display: flex;
        .avatar {
          width: 48px;
          height: 48px;
          border-radius: 12px;
          background-color: #d9d9d9;
          line-height: 48px;
          text-align: center;
        }
        .username {
          width: 30px;
          height: 30px;
          text-align: center;
          line-height: 30px;
          border-radius: 50%;
          background: #04c9be;
          color: #fff;
          margin-right: 4px;
        }
        .company-info {
          margin-left: 10px;
          height: 48px;
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          .title {
            color: #383c4e;
            font-weight: 500;
            font-size: 16px;
            font-family: PingFang SC, PingFang SC-Medium;
            span {
              font-size: 12px;
              // background: #f5f6f8;
              text-align: center;
              padding: 2px 8px;
              border-radius: 2px;
              color: #697086;
            }
          }
          .depart {
            font-size: 14px;
            color: #697086;
            font-weight: 400;
          }
        }
      }
      // 代办样式
      .todo-list {
        margin-top: 10px;
        display: flex;
        flex-wrap: wrap;
        .todo-item {
          width: 18%;
          height: 90px;
          display: flex;
          flex-direction: column;
          padding: 10px;
          justify-content: space-around;
          :nth-child(1) {
            color: #697086;
            font-size: 14px;
          }
          :nth-child(2) {
            color: #383c4e;
            font-size: 30px;
            font-weight: 500;
          }
        }
      }
      // 快捷入口
      .quick-entry {
        margin-top: 16px;
        display: flex;
        .entry-item {
          display: flex;
          flex-direction: column;
          align-items: center;
          margin-left: 60px;
          &:nth-child(1) {
            margin-left: 0px;
          }
          .entry-icon {
            width: 40px;
            height: 40px;
            border-radius: 10px;
            // background: #f5f6f8;

            background-size: cover;
            &.approval {
              background-image: url("../../assets/common/approval.png");
            }
            &.social {
              background-image: url("../../assets/common/social.png");
            }
            &.salary {
              background-image: url("../../assets/common/salary.png");
            }
            &.role {
              background-image: url("../../assets/common/role.png");
            }
            &.bpm {
              background-image: url("../../assets/common/bpm.png");
            }
          }
          span {
            color: #697086;
            font-size: 14px;
            margin-top: 8px;

            .link {
              text-decoration: none;
            }
          }
        }
      }
      // 图表数据
      .chart-container {
        display: flex;
        .chart-info {
          width: 240px;
          margin-top: 10px;
          .info-main {
            padding: 10px;
            display: flex;
            flex-direction: column;
            :nth-child(1) {
              font-size: 14px;
              color: #697086;
            }
            :nth-child(2) {
              margin-top: 10px;
              font-size: 30px;
              color: #04c9be;
              font-weight: 500;
            }
          }
          .info-list {
            // background: #f5f6f8;
            border-radius: 4px;
            padding: 12px 15px;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            .info-list-item {
              width: 50%;
              margin-top: 10px;
              display: flex;
              flex-direction: column;

              :nth-child(1) {
                font-size: 14px;
                color: #697086;
              }
              :nth-child(2) {
                margin-top: 10px;
                font-size: 30px;
                color: #383c4e;
                font-weight: 500;
              }
            }
          }
        }
        .chart {
          width: 100%;
          height: 350px;
        }
      }
      // 帮助链接
      .help {
        display: flex;
        .help-left {
          width: 40%;
        }
        .help-right {
          flex: 1;
          .calendar {
           height: 300px;
           overflow: auto;
           //美化滚动条
           &::-webkit-scrollbar {
             width: 5px;
           }
           &::-webkit-scrollbar-thumb {
             background-color: #04c9be;
             border-radius: 10px;
           }
           &::-webkit-scrollbar-track {
             background-color: #f5f6f8;
           }

          }
        }
        .help-list {
          .help-block {
            // background: #f5f6f8;
            border-radius: 4px;
            width: 264px;
            height: 54px;
            padding: 17px 10px;
            font-size: 14px;
            color: #697086;
            margin-top: 10px;
            i {
              width: 14px;
              height: 14px;
              display: inline-block;
              background-size: cover;
              vertical-align: middle;
            }
            i.icon-help {
              background-image: url("~@/assets/common/help.png");
            }
            i.icon-support {
              background-image: url("~@/assets/common/support.png");
            }
            i.icon-add {
              background-image: url("~@/assets/common/add.png");
            }
            i.icon-entry {
              background-image: url("~@/assets/common/entry.png");
            }
          }
        }
      }
      // 通知公告
      .information-list {
        margin-top: 20px;
        .information-list-item {
          display: flex;
          align-items: center;
          margin: 15px 0;
          img {
            width: 40px;
            height: 40px;
            border: 50%;
          }
          .col {
            color: #8a97f8;
          }
          div :nth-child(2) {
            color: #697086;
            font-size: 14px;
          }
        }
      }
    }
  }
}
</style>
